package com.xinqi.modules.course.comment.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.course.comment.domain.CommentGiveEntity;
import com.xinqi.modules.course.comment.mapper.CommentGiveMapper;
import com.xinqi.modules.course.comment.service.CommentGiveService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 栏目评论点赞表服务层实现
 *
 * @author: yyzhen
 * @date: 2023/03/20
 */
@Service("commentGiveService")
@RequiredArgsConstructor
public class CommentGiveServiceImpl extends BaseServiceImpl<CommentGiveMapper, CommentGiveEntity> implements CommentGiveService {

    /**
     * 根据评论与用户获取点赞
     *
     * @param comId
     * @param userId
     * @return
     */
    @Override
    public CommentGiveEntity selectByComIdAndUserId(Long comId, Long userId) {
        LambdaUpdateWrapper<CommentGiveEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(CommentGiveEntity::getComId, comId)
            .eq(CommentGiveEntity::getUserId, userId)
            .last("limit 1");
        return this.baseMapper.selectOne(wrapper);
    }

    /**
     * 根据评论删除点赞
     *
     * @param comId
     * @return
     */
    @Override
    public Boolean deleteByComId(Long comId) {
        LambdaUpdateWrapper<CommentGiveEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(CommentGiveEntity::getComId, comId);
        return this.remove(wrapper);
    }
}
